package com.yanqu.road.entity.activity.daomu.pvp;

/**
 * 怪物属性
 */
public class DaoMuPvpMonsterData {

    private int roomId;

    private String monsterId;

    private int faceId;

    private long attack;

    private int speed;

    private DaoMuPvpPosition position = new DaoMuPvpPosition();

    /**
     * 受击次数大于n次死亡
     */
    private int attackCnt;

    /**
     * 锁定的用户id
     */
    private long lockUserId;

    /**
     * 攻击时间
     */
    private long attackTime;

    /**
     * 碰撞时间
     */
    private long collisionTime;

    /**
     * 改变方向的时间
     */
    private long changeDirTime;

    /**
     * 池子索引
     */
    private int poolIndex;

    public DaoMuPvpMonsterData() {

    }

    public boolean isLive() {
        return attackCnt > 0;
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public String getMonsterId() {
        return monsterId;
    }

    public void setMonsterId(String monsterId) {
        this.monsterId = monsterId;
    }

    public int getFaceId() {
        return faceId;
    }

    public void setFaceId(int faceId) {
        this.faceId = faceId;
    }

    public long getAttack() {
        return attack;
    }

    public void setAttack(long attack) {
        this.attack = attack;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public DaoMuPvpPosition getPosition() {
        return position;
    }

    public void setPosition(DaoMuPvpPosition position) {
        this.position = position;
    }

    public int getAttackCnt() {
        return attackCnt;
    }

    public void setAttackCnt(int attackCnt) {
        this.attackCnt = attackCnt;
    }

    public long getLockUserId() {
        return lockUserId;
    }

    public void setLockUserId(long lockUserId) {
        this.lockUserId = lockUserId;
    }

    public long getAttackTime() {
        return attackTime;
    }

    public void setAttackTime(long attackTime) {
        this.attackTime = attackTime;
    }

    public long getCollisionTime() {
        return collisionTime;
    }

    public void setCollisionTime(long collisionTime) {
        this.collisionTime = collisionTime;
    }

    public long getChangeDirTime() {
        return changeDirTime;
    }

    public void setChangeDirTime(long changeDirTime) {
        this.changeDirTime = changeDirTime;
    }

    public int getPoolIndex() {
        return poolIndex;
    }

    public void setPoolIndex(int poolIndex) {
        this.poolIndex = poolIndex;
    }

    /**
     * 更新坐标
     */
    public void updatePosition() {
        long nowTime = System.currentTimeMillis();
        // 每毫秒的移动速度
        double speed = this.speed * 1.0 / 1000;
        double offsetTime = nowTime - position.getTime();
        double oldX = position.getX();
        double dx = position.getDirX();
        double offsetX = dx * speed * offsetTime;
        position.setX(oldX + offsetX);
        double oldY = position.getY();
        double dy = position.getDirY();
        double offsetY = dy * speed * offsetTime;
        position.setY(oldY + offsetY);
        position.setTime(nowTime);
    }

    /**
     * 获取怪物所在的坐标
     */
    public Coordinate getCoordinate() {
        return new Coordinate(position.getX(), position.getY());
    }
}
